home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
WINICONS
/
V12N11.ZIP
/
ABOUT.ZIP
/
ABOUT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-03-31
|
9KB
|
317 lines
{************************************************}
{ }
{ About box unit }
{ Copyright (c) 1993 by Danny Thorpe }
{ }
{ for Borland Pascal 7.0 }
{************************************************}
unit About;
interface
uses Winprocs, Wintypes, Objects, OWindows, ODialogs;
{$R About.res}
const
idShade = 100;
idBump = 101;
idHotKey = 103;
type
PPCharArray = ^TPCharArray;
TPCharArray = array [0..65520 div sizeof(PChar)] of PChar;
PCreditWindow = ^TCreditWindow;
TCreditWindow = object(TWindow)
Bitmap: HBitmap;
BitSize: TBitmap;
ScrollUnit: Integer;
ScrollRate: Integer;
ScrollPos: Integer;
FontHeight: Integer;
StringList: PPCharArray;
StringCount: Word;
constructor Init(AParent: PWindowsObject;
ABitmapName: PChar;
const AStringList: Array of PChar);
destructor Done; virtual;
function GetClassName: PChar; virtual;
procedure GetWindowClass(var WC: TWndClass); virtual;
procedure SetupWindow; virtual; { First place HWindow is valid }
procedure WMDestroy(var Msg: TMessage); { Last place HWindow is valid }
virtual wm_First + wm_Destroy;
procedure Paint(DC: HDC; var PS: TPaintStruct); virtual;
procedure ShowCredits; virtual;
procedure WMTimer(var Msg: TMessage);
virtual wm_First + wm_Timer;
end;
PAboutBox = ^TAboutBox;
TAboutBox = object(TDialog)
Title: PChar;
CreditWindow: PCreditWindow;
constructor Init(AParent: PWindowsObject;
ATitle, ABitmapName: PChar;
const AStringList: Array of PChar);
destructor Done; virtual;
procedure SetupWindow; virtual;
function GetResName: PChar; virtual;
procedure InitCreditWindow(ABitmapName: PChar;
const AStringList: array of PChar); virtual;
procedure ShowCredits(var Msg: TMessage);
virtual id_First + idHotKey;
end;
implementation
uses Strings;
constructor TCreditWindow.Init(AParent: PWindowsObject;
ABitmapName: PChar;
const AStringList: Array of PChar);
var
DC: HDC;
OldFont: HFont;
TM: TTextMetric;
begin
inherited Init(AParent, nil);
Attr.Style := ws_Child or ws_Visible;
Bitmap := LoadBitmap(HInstance, ABitmapName);
if Bitmap = 0 then
begin
Status := em_InvalidWindow;
Exit;
end;
GetObject(Bitmap, SizeOf(BitSize), @BitSize);
ScrollPos := 0;
DC := GetDC(0);
ScrollUnit := 2;
ScrollRate := 80;
OldFont := SelectObject(DC, GetStockObject(ANSI_VAR_FONT));
GetTextMetrics(DC, TM);
FontHeight := TM.tmHeight + TM.tmExternalLeading + 5;
SelectObject(DC, Oldfont);
ReleaseDC(0, DC);
StringList := @AStringList;
StringCount := High(AStringList)+1;
end;
destructor TCreditWindow.Done;
begin
inherited Done;
DeleteObject(Bitmap);
end;
function TCreditWindow.GetClassName: PChar;
begin
GetClassName := 'OWLAboutBitmap';
end;
procedure TCreditWindow.GetWindowClass(var WC: TWndClass);
begin
inherited GetWindowClass(WC);
WC.Style := cs_ByteAlignWindow; { for BitBlt speed }
WC.hbrBackground := GetStockObject(Black_Brush);
end;
procedure TCreditWindow.SetupWindow;
begin
inherited SetupWindow;
SetWindowPos(HWindow, 0, 0, 0, BitSize.bmWidth, BitSize.bmHeight,
swp_NoMove or swp_NoZOrder or swp_NoActivate or swp_NoRedraw);
end;
procedure TCreditWindow.WMDestroy(var Msg: TMessage);
begin
if ScrollPos <> 0 then { We're scrolling and need to kill the timer }
begin
KillTimer(HWindow, 1);
ScrollPos := 0;
end;
inherited WMDestroy(Msg);
end;
procedure TCreditWindow.Paint(DC: HDC; var PS: TPaintStruct);
var
R: TRect;
FirstLine, LastLine, Y: Integer;
procedure DrawBitmap(Y: Integer);
var
MemDC: HDC;
OldBits: HBitmap;
begin
MemDC:= CreateCompatibleDC(DC);
OldBits := SelectObject(MemDC, Bitmap);
BitBlt(DC, 0, Y, Attr.W, Attr.H, MemDC, 0, 0, srcCopy);
SelectObject(MemDC, OldBits);
DeleteDC(MemDC);
end;
begin
SaveDC(DC);
SetViewportOrg(DC, 0, -ScrollPos);
OffsetRect(PS.rcPaint, 0, ScrollPos);
with R do
begin
Left := 0;
Top := 0;
Right := Attr.W;
Bottom := Attr.H;
end;
if Bool(IntersectRect(R, PS.rcPaint, R)) then
begin
DrawBitmap(0);
with PS.rcPaint do
begin
if (R.Top < Top) and (R.Bottom > Top) then Top := R.Bottom;
if (R.Top < Bottom) and (R.Bottom > Bottom) then Bottom := R.Top;
if Top > Bottom then Top := Bottom;
end;
end;
if ScrollPos > 0 then { we're scrolling }
begin
FirstLine := (PS.rcPaint.Top - Attr.H) div FontHeight;
if FirstLine < 0 then FirstLine := 0;
if FirstLine < StringCount then
begin { we have text to draw }
SetTextAlign(DC, TA_Center);
SetBkColor(DC, 0);
SetTextColor(DC, RGB($ff,$ff,$ff));
LastLine := (PS.rcPaint.Bottom - Attr.H) div FontHeight;
for Y := FirstLine to LastLine do
if Y < StringCount then
TextOut(DC, Attr.W div 2, Y*FontHeight + Attr.H,
StringList^[Y], StrLen(StringList^[Y]));
end;
{ Paint second image of bitmap at bottom }
if PS.rcPaint.Bottom > (Attr.H+FontHeight*StringCount) then
DrawBitmap(Attr.H + FontHeight * StringCount);
end;
RestoreDC(DC, -1);
end;
procedure TCreditWindow.ShowCredits;
begin
SetTimer(HWindow, 1, ScrollRate, nil);
end;
procedure TCreditWindow.WMTimer(var Msg: TMessage);
begin
Inc(ScrollPos, ScrollUnit);
{ Check to see if it's time to stop scrolling }
if ScrollPos > Attr.H + FontHeight * StringCount then
begin
ScrollPos := 0;
KillTimer(HWindow, 1);
InvalidateRect(HWindow, nil, False);
end
else
ScrollWindow(HWindow, 0, -ScrollUnit, nil, nil);
UpdateWindow(HWindow);
end;
{*********************************************************}
constructor TAboutBox.Init(AParent: PWindowsObject;
ATitle, ABitmapName: PChar;
const AStringList: array of PChar);
begin
inherited Init(AParent, GetResName);
Title := StrNew(ATitle);
InitCreditWindow(ABitmapName, AStringList);
end;
destructor TAboutBox.Done;
begin
inherited Done;
if Title <> nil then
StrDispose(Title);
end;
procedure TAboutBox.SetupWindow;
var
RDialog,R,RBitWnd,RShade,RBump,ROk: TRect;
X8, Y8: Integer;
DC: HDC;
begin
inherited SetupWindow;
SetWindowText(HWindow, Title);
DC := GetDC(HWindow);
X8 := GetDeviceCaps(DC,LogPixelsX) div 8; { 1/8 inch }
Y8 := GetDeviceCaps(DC,LogPixelsY) div 8;
ReleaseDC(HWindow, DC);
GetClientRect(GetDlgItem(HWindow, idShade), RShade);
GetClientRect(GetDlgItem(HWindow, idBump), RBump);
GetClientRect(GetDlgItem(HWindow, idOK), ROk);
GetClientRect(CreditWindow^.HWindow, RBitWnd);
RShade.Top := Y8;
RShade.Left := X8;
if RShade.Right < RBitWnd.Right + 2*X8 then
RShade.Right := RBitWnd.Right + 2*X8;
if RShade.Bottom < RBitWnd.Bottom + 2*Y8 then
RShade.Bottom := RBitWnd.Bottom + 2*Y8;
with RDialog do
begin
GetWindowRect(HWindow, RDialog);
GetClientRect(HWindow, R);
Right := Right - Left - R.Right;
Bottom := Bottom - Top - R.Bottom;
Right := Right + X8 + RShade.Right + X8; { 1/8 inch margins }
Bottom := Bottom + Y8 + RShade.Bottom
+ Y8 + RBump.Bottom
+ Y8 + ROk.Bottom + Y8;
if Parent <> nil then
begin
GetWindowRect(Parent^.HWindow, R);
{ Center dialog in parent's window }
Left := R.Left + (R.Right - R.Left) div 2 - Right div 2;
Top := R.Top + (R.Bottom - R.Top) div 2 - Bottom div 2;
end;
SetWindowPos(HWindow, 0, Left, Top, Right, Bottom,